package com.example.mobile2021606145zbq0407homework;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity9 extends AppCompatActivity {

    private TextView tvMainTitle8;
    private TextView tvMain82;
    private TextView tvMain83;
    private TextView tvLirun;
    private EditText edtEightOne;
    private Button btn8;
    private TextView TVResult8;
    double num1 = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main9);
        initView();
        btn8.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String a = edtEightOne.getText().toString();
                if (a.length() == 0) {
                    Toast.makeText(MainActivity9.this, "请输入金额", Toast.LENGTH_SHORT).show();
                } else {
                    double b = Double.parseDouble(a);
                    if (b <= 100000) {
                        num1 = (b * 0.1);
                        TVResult8.setText(String.valueOf(num1));
                    }
                    if (100000 < b & b < 200000) {
                        num1 = 100000 * 0.1 + (b - 100000) * 0.075;
                        TVResult8.setText(String.valueOf(num1));
                    }
                    if (2000000 < b & b < 400000) {
                        num1 = 100000 * 0.1 + 100000 * 0.075 + (b - 200000) * 0.005;
                        TVResult8.setText(String.valueOf(num1));
                    }
                    if (400000 < b & b < 1000000) {
                        num1 = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.005 + (b - 400000) * 0.015;
                        TVResult8.setText(String.valueOf(String.valueOf(num1)));
                    }
                    if (b > 1000000) {
                        num1 = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.005 + 600000 * 0.015 + (b - 1000000);
                        TVResult8.setText(String.valueOf(num1));
                    }
                }
            }
        });
    }

    private void initView() {
        tvMainTitle8 = (TextView) findViewById(R.id.tv_main_title8);
        tvMain82 = (TextView) findViewById(R.id.tv_main_8_2);
        tvMain83 = (TextView) findViewById(R.id.tv_main_8_3);
        tvLirun = (TextView) findViewById(R.id.tv_lirun);
        edtEightOne = (EditText) findViewById(R.id.edt_eight_one);
        btn8 = (Button) findViewById(R.id.btn_8);
        TVResult8 = (TextView) findViewById(R.id.TV_result_8);
    }
}